package com.groupseven.happycampus.common.instener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.groupseven.happycampus.common.bo.BicycleBo;
import com.groupseven.happycampus.common.pojo.Bicycle;
import com.groupseven.happycampus.service.BicycleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("prototype")     // 注意 这里要设置成多例模式
public class WebBicycleListener extends AnalysisEventListener<BicycleBo> {

    @Autowired
    BicycleService bicycleService;

    @Override
    public void invoke(BicycleBo data, AnalysisContext analysisContext) {
        System.out.println(data);
        Bicycle bicycle = new Bicycle();
        // 属性拷贝
        BeanUtils.copyProperties(data,bicycle);
        bicycleService.bicycleAdd(bicycle);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
